package net.xo68.destiny.manager.mapper;


import net.xo68.destiny.manager.entity.JobDetail;
import org.apache.ibatis.annotations.*;
import java.util.List;

/** 
 * JobDetail mybatis mapper
 * @author wuxie(16349023@qq.com)
 * @date 2020年12月21日 21:43:52
 *
 */
public interface JobDetailMapper {


	
	@Select("SELECT * FROM destiny_job_detail WHERE job_id = #{jobId}")
    @Results(value = { 
    @Result(id = true, column = "job_id", property = "jobId"),
        @Result(column = "job_name", property = "jobName"),
        @Result(column = "work_group", property = "workGroup"),
        @Result(column = "job_description", property = "jobDescription"),
        @Result(column = "sched_type", property = "schedType"),
        @Result(column = "job_type", property = "jobType"),
        @Result(column = "job_handler", property = "jobHandler"),
        @Result(column = "update_time", property = "updateTime"),
        @Result(column = "operator", property = "operator"),
        @Result(column = "operator_nice", property = "operatorNice"),
        @Result(column = "worker_route_strategy", property = "workerRouteStrategy"),
        @Result(column = "worker_execute_mode", property = "workerExecuteMode"),
        @Result(column = "retry_count", property = "retryCount"),
        @Result(column = "execute_timeout", property = "executeTimeout"),
        @Result(column = "last_execute_state", property = "lastExecuteState")
    })
    JobDetail find(@Param("jobId") Long jobId);
	
	@Select("SELECT * FROM destiny_job_detail")
    @Results(value = { 
    @Result(id = true, column = "job_id", property = "jobId"),
        @Result(column = "job_name", property = "jobName"),
        @Result(column = "work_group", property = "workGroup"),
        @Result(column = "job_description", property = "jobDescription"),
            @Result(column = "sched_type", property = "schedType"),
        @Result(column = "job_type", property = "jobType"),
        @Result(column = "job_handler", property = "jobHandler"),
        @Result(column = "update_time", property = "updateTime"),
        @Result(column = "operator", property = "operator"),
        @Result(column = "operator_nice", property = "operatorNice"),
        @Result(column = "worker_route_strategy", property = "workerRouteStrategy"),
        @Result(column = "worker_execute_mode", property = "workerExecuteMode"),
        @Result(column = "retry_count", property = "retryCount"),
        @Result(column = "execute_timeout", property = "executeTimeout"),
        @Result(column = "last_execute_state", property = "lastExecuteState")
    })
    List<JobDetail> list();

    @Select("<script>" +
            "SELECT * FROM destiny_job_detail where job_id in " +
            "<foreach item='jobId' index='index' collection='jobs' open='(' separator=',' close=')'>" +
            "#{jobId}" +
            "</foreach>" +
            "</script>")
    @Results(value = {
            @Result(id = true, column = "job_id", property = "jobId"),
            @Result(column = "job_name", property = "jobName"),
            @Result(column = "work_group", property = "workGroup"),
            @Result(column = "job_description", property = "jobDescription"),
            @Result(column = "sched_type", property = "schedType"),
            @Result(column = "job_type", property = "jobType"),
            @Result(column = "job_handler", property = "jobHandler"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "operator", property = "operator"),
            @Result(column = "operator_nice", property = "operatorNice"),
            @Result(column = "worker_route_strategy", property = "workerRouteStrategy"),
            @Result(column = "worker_execute_mode", property = "workerExecuteMode"),
            @Result(column = "retry_count", property = "retryCount"),
            @Result(column = "execute_timeout", property = "executeTimeout"),
            @Result(column = "last_execute_state", property = "lastExecuteState")
    })
    List<JobDetail> listByJobs(@Param("jobs")List<Long> jobs);
	
	@Insert("insert into destiny_job_detail (job_id ,job_name ,work_group ,job_description ,job_type ,job_handler ,update_time ,operator ,operator_nice ,worker_route_strategy ,worker_execute_mode ,retry_count ,execute_timeout ,last_execute_state ) values (#{jobId} , #{jobName} , #{workGroup} , #{jobDescription} , #{jobType} , #{jobHandler} , #{updateTime} , #{operator} , #{operatorNice} , #{workerRouteStrategy} , #{workerExecuteMode} , #{retryCount} , #{executeTimeout} , #{lastExecuteState}  )")
    @Options(useGeneratedKeys = true, keyProperty = "jobId")
    int insert(JobDetail jobDetail);
	
	@Update({"update destiny_job_detail set",
      " job_name=#{jobName}, work_group=#{workGroup}, job_description=#{jobDescription}, job_type=#{jobType}, job_handler=#{jobHandler}, update_time=#{updateTime}, operator=#{operator}, operator_nice=#{operatorNice}, worker_route_strategy=#{workerRouteStrategy}, worker_execute_mode=#{workerExecuteMode}, retry_count=#{retryCount}, execute_timeout=#{executeTimeout}, last_execute_state=#{lastExecuteState} ",
      "where job_id = #{jobId}"
    })
    int update(JobDetail jobDetail);

	@Delete("delete FROM destiny_job_detail WHERE job_id = #{jobId}")
	int delete(@Param("jobId") Long jobId);
}